package jiakuang2;
import java.util.HashMap;
import java.util.Map;
public class Studay4 {
    private int id;
    private String newsName;
    private String userName;
//无参构造方法
    public Studay4(){}
    //有参构造方法
    public Studay4(int id, String newsName, String userName) {
        this.id = id;
        this.newsName = newsName;
        this.userName = userName;
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getNewsName() {
        return newsName;
    }
    public void setNewsName(String newsName) {
        this.newsName = newsName;
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public static void main(String[] args) {
        //创建数据

        Studay4 th=new Studay4(1,"火山爆发","狱中");
        Studay4 th1=new Studay4(2,"美国分类","狗肉");
        Studay4 th2=new Studay4(3,"日本沉没","中国");
        Studay4 th3=new Studay4(4,"第四次世界大战爆发","全世界");
        //创建集合
        Map studay4 =new HashMap();
        //添加数据
        studay4.put(1,th);
        studay4.put(2,th1);
        studay4.put(3,th2);
        studay4.put(4,th3);
        //遍历和增
        for(Object o: studay4.values()){
            //类型转换
            Studay4 te=(Studay4) o;
            System.out.println("新闻的id:"+te.getId()+"新闻的标题:"+te.getNewsName()+"新闻的作者:"+te.getUserName());
        }
        //删
        studay4.remove(3,th2);
        for(Object P: studay4.values()){
            Studay4 te1=(Studay4) P;
            System.out.println("新闻的id:"+te1.getId()+"新闻的标题:"+te1.getNewsName()+"新闻的作者:"+te1.getUserName());
        }
        //改
        studay4.put(1,th1);
        for(Object a: studay4.values()){
            Studay4 th5=(Studay4) a;
            System.out.println("新闻的id:"+th5.getId()+"新闻的标题:"+th5.getNewsName()+"新闻的作者:"+th5.getUserName());
        }

    }
}
